import NexBidResponse from "./models/nex-bid-response";
import NexBidRequest from "./models/nex-bid-request";
import RixBidRequest from "./models/rix-bid-request";
const convertToRixBidRequest = (bidRequest: NexBidRequest): RixBidRequest => {
  // 创建一个新的标准 Bid Request 对象
  const rixBidRequest: RixBidRequest = {
    id: bidRequest.id,
    imp: [], // 根据需要处理 imp 字段
    site: bidRequest.app, // 根据需要处理 site 或 app 字段
    device: bidRequest.device, // 根据需要处理 device 字段
    user: bidRequest.user, // 根据需要处理 user 字段
    at: 1, // 设置竞价类型为第一价格竞价
    tmax: bidRequest.tmax,
    cur: bidRequest.cur,
    bcat: bidRequest.bcat,
    wseat: bidRequest.wseat,
    // 根据需要添加其他标准字段
  };

  // 根据自定义格式处理 imp 字段
  bidRequest.imp.forEach((customImp) => {
    const standardImp = {
      id: customImp.id,
      tagid: customImp.tagid, // 或其他字段映射
      bidfloorcur: customImp.bidfloorcur,
      bidfloor: customImp.bidfloor,
      // 根据需要添加其他标准字段
    };
    rixBidRequest.imp.push(standardImp);
  });

  // 根据需要添加其他转化逻辑

  return rixBidRequest;

}

const convertToNexBidResponse = ():NexBidResponse|null => {
  // 示例BidResponse对象
  const nexBidResponse: NexBidResponse = {
    id: "F36BABA54B414D45A9D313AA1450073C",
    bidid: "100002_200004_1000014",
    cur: "CNY",
    seatbid: [
      {
        bid: [
          {
            id: "100002_200004_1000014_0",
            impid: "902",
            nurl: "http://test.xxx.com?id=${AUCTION_ID}&bidid=${AUCTION_BID_ID}&impid=${AUCTION_IMP_ID}&price=${AUCTION_PRICE}&cur=${AUCTION_CURRENCY}",
            price: 600,
            crid: "1000014",
            pvm: [
              "http://g1.163.com/madfeedback1",
              "http://g1.163.com/madfeedback2",
              "http://g1.163.com/madfeedback3",
              "http://g1.163.com/madfeedback4",
              "http://g1.163.com/madfeedback5",
            ],
            clickm: [
              "http://g1.163.com/madfeedback6",
              "http://g1.163.com/madfeedback7",
              "http://g1.163.com/madfeedback8",
              "http://g1.163.com/madfeedback9",
              "http://g1.163.com/madfeedback10",
            ],
            ext: {
              macros: [
                {
                  macro: "${bid_a}",
                  value: "a",
                  expression: [],
                },
                {
                  macro: "${bid_b}",
                  value: "b",
                  expression: [1, 3],
                },
              ],
              style: 3,
              title: "我是空格空格空格空格空格创意style 3",
              isFullScreen: 0,
              linkUrl: "http://www.csdn.net",
              adm: [
                {
                  url: "http://wwww.source.com/aei2.jpg",
                  type: 0,
                  w: 1080,
                  h: 1920,
                },
              ],
              advertiser: {
                id: "1",
                industry: "01",
                subIndustry: "0101",
              },
            },
            eventTracker: [
              {
                type: 5,
                url: "https://www.tracker.com/callapp/ok?id=32e89e301d7326h8c",
              },
            ],
            interact_mode: 1,
            need_coordinate: 0,
          },
        ],
      },
    ],
  };
  return nexBidResponse
}

export {
  convertToRixBidRequest,
  convertToNexBidResponse,
}